function change(val) {
	if (val == "high") {
	return '<span style="color:red;">' + val + '</span>';
	} else if (val == 'medium') {
	return '<span style="color:orange;">' + val + '</span>';
	} else if (val == 'low') {
	return '<span style="color:green;">' + val + '</span>';
	} else if (val == 'info') {
	return '<span style="color:blue;">' + val + '</span>';
	}
	return val;
}
 
Ext.define('disp',{
extend: 'Ext.data.Model',
fields: [
	{name: 'event', mapping: 'alertAttributes > event'},
	'level',
	'type',
	'description',
	'User',
	'Status',
	'App',
	'Filename',
	'Id'
]
});

var store = Ext.create('Ext.data.Store', {
        pageSize: 50,
	model: 'disp',
        remoteSort: true,
	proxy: {
    	type: 'ajax',
    	url: 'disp_cor.php',
    	reader: {
		type: 'xml',
		record: 'alert',
		id: 'Id',
		totalRecords: 'total'
		}
	}
});
 

 

    var pluginExpanded = true;
    var grid = Ext.create('Ext.grid.Panel', {
 	forceFit: true,
 
        store: store,
        disableSelection: true,
        loadMask: true,
 
        // grid columns
        columns: [
	    {text: "event", width: 150, dataIndex: 'event', sortable: true},
	    {text: "level", width: 50, dataIndex: 'level', renderer : change, sortable: true},
	    {text: "type",  width: 100, dataIndex: 'type', sortable: true},
	    {text: "description", flex: 1, width: 100,  dataIndex: 'description', sortable: true}
	],
    bbar: Ext.create('Ext.PagingToolbar', {
            pageSize: 10,
            store: store,
            displayInfo: true,
	    items:[
                '-', {
                text: 'More info',
                pressed: pluginExpanded,
                enableToggle: true,
                toggleHandler: function(btn, pressed) {
                    var preview = Ext.getCmp('gv').getPlugin('preview');
                    preview.toggleExpanded(pressed);
                }
            }]
        })
    
 
    });











 
 
var task = {
    run: function(){ 
     store.load();
    },
    interval: 1000 * 120  
};
var runner = new Ext.util.TaskRunner();
runner.start(task);
 
